<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>JS继承</h2>
</body>
<script>
    //ES5继承

    //1.第一步先创建一个父类
    function Person(name = '无名', age = 0) {
        this.name = name
        this.age = age
    }

    //create方法
    Person.prototype.create = function() {
        console.log(`${this.name}创建新生活`)
    }

    //drive方法
    Person.prototype.drive = function() {
        console.log(`${this.name}能开车`)
    }


    //2.第二步创建一个子类
    function Child(name, age, address = '地球人') {
        //借用构造函数继承
        Person.call(this, name, age)
        this.address = address

    }

    //原型链继承
    Child.prototype = new Person()


    //play方法
    Child.prototype.play = function() {
        console.log(`${this.name}能打游戏`)
    }

    const c1 = new Child('王五', 28, '北京')


    console.log(c1.address)
    c1.play()
    c1.create()
    console.log(c1.name)
    console.log(c1.age)


    //3.子类如何继承父类---原型链继承--只能继承方法，不能继承属性
</script>

</html>